package com.onepower.core.modules.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.onepower.core.modules.repository.entity.MatchScoreIpadArithmetic;
import com.onepower.core.modules.repository.entity.MatchScoreOrderRule;
import com.onepower.core.modules.repository.entity.MatchScoreRule;
import com.onepower.core.modules.repository.entity.MatchScoreStatusRule;
import com.onepower.core.modules.repository.mapper.MatchScoreRuleMapper;
import com.onepower.core.modules.service.IMatchScoreIpadArithmeticService;
import com.onepower.core.modules.service.IMatchScoreOrderRuleService;
import com.onepower.core.modules.service.IMatchScoreRuleService;
import com.onepower.core.modules.service.IMatchScoreStatusRuleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class IMatchScoreRuleServiceImpl extends ServiceImpl<MatchScoreRuleMapper, MatchScoreRule> implements IMatchScoreRuleService {

    @Override
    public MatchScoreRule getScoreRule(Integer id) {
        return null;
    }

    @Autowired
    IMatchScoreStatusRuleService iMatchScoreStatusRuleService;

    @Autowired
    IMatchScoreIpadArithmeticService matchScoreIpadArithmeticService;

    @Autowired
    IMatchScoreOrderRuleService matchScoreOrderRuleService;

    @Override
    public void updateScoreRule(Integer id, String name) {
        MatchScoreRule matchScoreRule = new MatchScoreRule();
        matchScoreRule.setUpdateTime(new Date());
        matchScoreRule.setName(name);
        matchScoreRule.setId(id);
        baseMapper.updateById(matchScoreRule);
    }

    @Override
    public void save(String name) {
        MatchScoreRule matchScoreRule = new MatchScoreRule();
        matchScoreRule.setCreateTime(new Date());
        matchScoreRule.setName(name);
        baseMapper.insert(matchScoreRule);

        MatchScoreStatusRule matchScoreStatusRule = new MatchScoreStatusRule();
        matchScoreStatusRule.setRuleId(matchScoreRule.getId());
        matchScoreStatusRule.setStatus(0);
        matchScoreStatusRule.setCreateTime(new Date());
        iMatchScoreStatusRuleService.save(matchScoreStatusRule);

        MatchScoreIpadArithmetic matchScoreIpadArithmetic1 = new MatchScoreIpadArithmetic();
        matchScoreIpadArithmetic1.setRuleId(matchScoreRule.getId());
        matchScoreIpadArithmetic1.setType(1);
        matchScoreIpadArithmetic1.setSelectRule(1);
        matchScoreIpadArithmetic1.setArithmeticRule(1);
        matchScoreIpadArithmetic1.setName("精准度");
        matchScoreIpadArithmeticService.save(matchScoreIpadArithmetic1);

        MatchScoreIpadArithmetic matchScoreIpadArithmetic2 = new MatchScoreIpadArithmetic();
        matchScoreIpadArithmetic2.setRuleId(matchScoreRule.getId());
        matchScoreIpadArithmetic2.setType(2);
        matchScoreIpadArithmetic2.setSelectRule(2);
        matchScoreIpadArithmetic2.setArithmeticRule(2);
        matchScoreIpadArithmetic2.setName("表现力");
        matchScoreIpadArithmeticService.save(matchScoreIpadArithmetic2);

        MatchScoreOrderRule matchScoreOrderRule = new MatchScoreOrderRule();
        matchScoreOrderRule.setOrderRuleId(1);
        matchScoreOrderRule.setCreateTime(new Date());
        matchScoreOrderRule.setRuleId(matchScoreRule.getId());
        matchScoreOrderRuleService.save(matchScoreOrderRule);
    }

    @Override
    public List<MatchScoreRule> scoreRuleList() {
        List<MatchScoreRule> matchScoreRuleList = baseMapper.selectScoreRuleList();
        return matchScoreRuleList;
    }

    @Override
    public MatchScoreRule getScoreRuleByName(String name) {
        MatchScoreRule matchScoreRule = baseMapper.selectScoreRuleByName(name);
        return matchScoreRule;
    }

    @Override
    public void delete(Integer[] ids) {

    }
}
